package com.example.adms.depart.controller;

import com.example.adms.depart.dto.PageParams;
import com.example.adms.depart.entity.Depart;
import com.example.adms.depart.service.DepartService;
import com.example.adms.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/depart")
public class DepartController {

    @Autowired
    private DepartService departService;

    /**
     * 根据用户id查对应部门
     * @param token
     * @return
     */
    @GetMapping("/getDepartById")
    public Result getDepartById(@RequestHeader("Authorization") String token){
        return departService.getDepartById(token);
    }

    /**
     * 条件分页
     * @return
     */
    @PostMapping("/getDepartListWithCondition")
    public Result getDepartListWithCondition(@RequestBody PageParams pageParams){
        return departService.getDepartListWithCondition(pageParams);
    }

    /**
     * 获取所有部门
     * @return
     */
    @GetMapping("/getDepartList")
    public Result getDepartList(){
        return Result.success(departService.getDepartList());
    }

    /**
     * 添加、修改部门
     * @param depart
     * @return
     */
    @PostMapping("/addOrUpdateDepart")
    public Result addOrUpdateDepart(@RequestBody Depart depart){
        return departService.addOrUpdateDepart(depart);
    }
}
